package com.nl.controller.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.nl.controller.web.bean.ChangeData;
import com.nl.controller.web.service.ChangeSynchronizationInterfaceService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; 

@RestController
@Slf4j
@RequestMapping("SmsChange")
public class ChangeSynchronizationController {
	@Autowired
	private ChangeSynchronizationInterfaceService changeSynchronizationInterfaceService;
	

	private String getStreamSeq() {
        String streamSeq = changeSynchronizationInterfaceService.getStreamSeq();
        log.debug("获取流水序列号：{}", streamSeq);
        return streamSeq;
    }
	
	@ApiOperation(value = "通过项目id获取变更信息", notes = "通过项目id获取变更信息")
	@PostMapping("findChangeByMgrId")
	public Map<String, Object> changeSynchronization(@RequestParam(value = "mgrId", required = false) String mgrId){
		 /*List<Content> contentList = new ArrayList<Content>();*/
		 JSONObject json = new JSONObject();
		 ChangeData changeData = changeSynchronizationInterfaceService.findChangeByMgrId(mgrId);
		 changeData.setStreamSeq(getStreamSeq());
		 log.info(" 项目信息：{}", changeData.toString());
		 /*json.put("changeData",changeData);*/
		 json.put("mgrId",changeData.getMgrId());
		 json.put("checkState",changeData.getCheckState());
		 json.put("mgrState",changeData.getMgrState());
		 json.put("sendStart",changeData.getSendStart());
		 json.put("sendEnd",changeData.getSendEnd());
		 json.put("streamSeq",changeData.getStreamSeq());
		 json.put("flag","program_update");
		 System.out.println("json:"+json.toString());
		 Map<String, Object> map = changeSynchronizationInterfaceService.changeSynchronization(json);
//		 contentList = (List<Content>) map.get("content");/
		 log.info(" 返回信息：{}", map.toString());
		 return map;
	 }

}
